﻿using Public_Defined;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace Login_Server
{
    public class Servser_Mgr
    {
        private Login_Defined.Server_Info server_info;

        private Login_Defined.Msg_Struct<string> response_msg;

        private static Dictionary<UInt16, Login_Defined.Server_Info> server_list = new Dictionary<ushort, Login_Defined.Server_Info>();
        public Servser_Mgr()
        {
            response_msg.Code = 200;
            response_msg.Msg = "ok";
            response_msg.Data = "成功";
        }

        public delegate void Delegate_Server_Listener(Login_Defined.Server_Info serverinfo);

        Delegate_Server_Listener serverListener;

        /**
         * 与游戏服务器保持连接 维护server_list
         */
        public void Holds_Connect(Login_Defined.Server_Info serverinfo)
        {

        }

        public Login_Defined.Msg_Struct<string> add_server_info(Login_Defined.Server_Info serverinfo)
        {
            try
            {
                server_list.Add(serverinfo.Server_id, serverinfo);
                response_msg.Code = 200;
                response_msg.Msg = "ok";
                response_msg.Data = "成功";

                //启用线程、执行委托、与游戏服务器进行连接
                serverListener = Holds_Connect;
                serverListener.Invoke(serverinfo);

                return response_msg;
            }
            catch (Exception e)
            {
                response_msg.Code = -100;
                response_msg.Msg = "error";
                response_msg.Data = "添加失败";
                return response_msg;
                throw e;
            }
        }
    }
}
